/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.PA165.musiclibrarybackend.services;

import cz.muni.fi.PA165.musiclibraryapi.dto.AuthorDTOInterface;
import cz.muni.fi.PA165.musiclibraryapi.services.AuthorService;
import cz.muni.fi.PA165.musiclibrarybackend.dao.AuthorDAO;
import cz.muni.fi.PA165.musiclibrarybackend.entities.Author;
import cz.muni.fi.PA165.musiclibrarybackend.transfers.AuthorT;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author Dominik
 */
@Service
@Transactional
public class AuthorServiceImpl implements AuthorService, Serializable{

    private AuthorDAO authorDAO;
    
    public void setAuthorDAO(AuthorDAO authorDAO) {
        this.authorDAO = authorDAO;
    }
    
    public void createAuthor(AuthorDTOInterface author) {
        authorDAO.createAuthor(AuthorT.DTOtoAuthor(author));
    }

    public AuthorDTOInterface getAuthor(Long id) {
        return AuthorT.AuthorToDTO(authorDAO.getAuthor(id));
    }

    public List<AuthorDTOInterface> getAllAuthors() {
        List<AuthorDTOInterface> allAuthorsDTO = new ArrayList();
        List<Author> allAuthors = authorDAO.getAllAuthors();
        for(Author author : allAuthors) {
            allAuthorsDTO.add(AuthorT.AuthorToDTO(author));
        }
        return allAuthorsDTO;
    }

    public void updateAuthor(AuthorDTOInterface author) {
        authorDAO.updateAuthor(AuthorT.DTOtoAuthor(author));
    }

    public void deleteAuthor(AuthorDTOInterface author) {
        authorDAO.deleteAuthor(AuthorT.DTOtoAuthor(author));
    }
    
}
